package com.itheima.app.controller;

import com.itheima.app.manager.MovementManager;
import com.itheima.app.manager.UserManager;
import com.itheima.domain.db.Movement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.ws.rs.GET;
import java.io.IOException;
import java.util.Map;

/**
 * @author zsk
 * @create 2022-03-17-16:13
 */
@RestController
public class MovementController {

    //依赖注入manager
    @Autowired
    private MovementManager movementManager;

    //发表动态
    @PostMapping("/movements")
    //接收参数：动态信息与图片信息
    public void saveMovement(Movement movement, MultipartFile[] imageContent) throws IOException {
        //调用manager
        movementManager.saveMovement(movement,imageContent);
    }

    //查看我的动态
    @GetMapping("/movements/all")
    public ResponseEntity findByMovementPage(
            Long userId,
            @RequestParam(value = "page",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize){

        //调用manager
        return movementManager.findByMovementPage(userId,pageNum,pageSize);
    }

    //查询好友动态
    @GetMapping("/movements")
    public ResponseEntity findByFriendMovement(
            @RequestParam(value = "page",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize
    ){

        //调用manager
        return movementManager.findByFriendMovement(pageNum,pageSize);

    }

    //查询推荐动态
    @GetMapping("/movements/recommend")
    public ResponseEntity findRecommendMovementByPage(
            @RequestParam(value = "page",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize
    ){
        //调用manager
        return movementManager.findRecommendMovementByPage(pageNum,pageSize);


    }

    //设置点赞
    @GetMapping("/movements/{publishId}/like")
    public ResponseEntity movementLike(@PathVariable String publishId){
        //调用manager
        return movementManager.movementLike(publishId);

    }


    //取消点赞
    @GetMapping("/movements/{publishId}/dislike")
    public ResponseEntity movementDeleteLike(@PathVariable String publishId){
        //调用manager
        return movementManager.movementDeleteLike(publishId);
    }

    //设置喜欢
    @GetMapping("/movements/{publishId}/love")
    public ResponseEntity movementLove(@PathVariable String publishId){

        //调用manager
        return movementManager.movementLove(publishId);

    }

    //取消喜欢
    @GetMapping("/movements/{publishId}/unlove")
    public ResponseEntity movementDeleteLove(@PathVariable String publishId){

        //调用manager
        return movementManager.movementDeleteLove(publishId);

    }

    //展示单条动态
    @GetMapping("/movements/{publishId}")
    public ResponseEntity findMovementVoById(@PathVariable String publishId){
        //调用manager
        return movementManager.findMovementVoById(publishId);
    }

    //展示动态评论
    @GetMapping("/comments")
    public ResponseEntity findCommentVoByPage(
            @RequestParam("movementId") String publishId,
            @RequestParam(value = "page",defaultValue = "1")Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize
    ){
        //调用manager
        return movementManager.findCommentVoByPage(publishId,pageNum,pageSize);

    }

    //发表评论
    @PostMapping("/comments")
    public void movementComment(@RequestBody Map<String,String> map){
        //获取参数
        String publishId = map.get("movementId");
        String content = map.get("comment");

        //调用manager
        movementManager.movementComment(publishId,content);
    }


}
